<?php

namespace App\Admin\Controllers;

use App\Admin\Actions\LazyFormAction;
use App\Admin\Actions\ModalAction;
use App\Admin\Forms\LazyFormDemo;
use App\Http\Controllers\Controller;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;

class HomeController extends Controller
{
    public function index(Content $content)
    {
        return $content
            ->header('欢迎登录，'.Admin::user()->name)
            ->body(view('admin/home/index'));
    }

    public function demo(Content $content){
        $grid=new Grid(new \App\Models\AdminConfig());
        $grid->column('id','ID');
        $grid->column('title','标题');
        $grid->column('name','标识');
        $grid->column('group','分组');
        $grid->column('type','输入类型');
        $grid->disableDeleteButton();
        $grid->disableCreateButton();
        $grid->setActionClass(Grid\Displayers\Actions::class);//将列表的编辑删除菜单改为横排显示
        $grid->actions(function(Grid\Displayers\Actions $actions){
            $actions->append(new LazyFormAction(LazyFormDemo::class,$actions->row->toArray(),"审核",'feather icon-check-circle'));
            $actions->append(new ModalAction(admin_url('order/cancel'),["id"=>1],'自定义URL'));
        });
        return $content->title("Demo")->body($grid->render());
    }
}
